const ApiUrl = 'http://121.36.218.108/';
// const ApiUrl = '/api/';
import {getStore,toast} from './util.js'

function request(url, data = {}, method = 'Get') {
  let contentType = 'application/json';
  return new Promise(function (resolve, reject) {
    uni.request({
      url: url,
      data: data,
      method: method,
	  
      header: {
        'Content-Type': contentType,
      },
      success: function (res) {
        if (res.statusCode == 200) {
          resolve(res.data)
        } else if(res.data.resultCode == '401' || res.data.resultCode == '403'){
					toast('error',res.data.resultMessage)
				  uni.clearStorageSync();
          uni.navigateTo({
            url: '/pages/login/login',
          })
				}else{
          reject(res.message)
        }
      },
      fail: function (err) {
        reject('服务器连接失败');
      }
    })
  })
}

function post(link, data) {
  let url = ApiUrl;
  return request(url + link, data, 'POST');
}

function get(link, data) {
  let url = ApiUrl;
  return request(url + link, data, 'GET');
}
//上传图片

let apis = {}

//登录接口
apis.UserApi = (data) => post('api/UserApi', data);

// 新增门店
apis.ShopApi = (data) => post('api/ShopApi',data)

//获取门店
apis.getShopApi = (data) => get('api/ShopApi',data)

//新增商品
apis.ShopOrderApi = (data) => post('api/ShopOrderApi',data)

//获取商品
apis.getShopOrderApi = (data) => get('api/ShopOrderApi',data)

// 我的业绩api/ReportApi
apis.getReportApi = (data) => get('api/ReportApi',data);

export default apis

